Skip to content

feat(document): use matching markdown file as folder page content#58

Open
geopanther wants to merge 2 commits into
mainfrom
feat/folder-page-content
Open

feat(document): use matching markdown file as folder page content#58
geopanther wants to merge 2 commits into
mainfrom
feat/folder-page-content

Conversation

@geopanther

@geopanther geopanther commented May 13, 2026

Copy link
Copy Markdown
Owner

Summary

When a markdown file shares its stem with a sibling directory (e.g., sub-folder.md next to sub-folder/), use its content as the body of the folder page instead of creating an empty folder page and a separate content page.

Opt-in via --use-folder-content-file flag — no implicit behavior change.

Adapted from iamjackg/md2cf#141 by @sheyifan.

Changes

  • New CLI flag --use-folder-content-file (opt-in)
  • Pre-scan walk identifies matching files only when flag is enabled
  • Folder pages created with content from matching markdown file (body, attachments, relative links, labels)
  • Matching files excluded from normal page processing to avoid duplication

Differences from upstream

  • Opt-in behavior via explicit CLI flag (upstream is always-on)
  • Removed debug prints left in the original PR
  • Kept title collision detection (upstream removed it)
  • Proper type annotations
  • Front matter labels passed through to folder page

Tests

  • test_get_pages_from_directory_folder_content_from_matching_md — verifies opt-in behavior
  • test_get_pages_from_directory_folder_content_disabled_by_default — verifies no change without flag
  • All 24 document tests pass

When a markdown file shares its stem with a sibling directory
(e.g., sub-folder.md next to sub-folder/), use its content as the
body of the folder page instead of creating an empty folder page and
a separate content page. The markdown file is excluded from normal
page processing to avoid duplication.

Adapted from iamjackg/md2cf#141 by @sheyifan.
@geopanther

Copy link
Copy Markdown
Owner Author

Maintainer Review

Verdict: ⚠️ Approve with reservations

Useful feature — many documentation systems (MkDocs, Hugo) use this convention. However, this is implicit behavior that could surprise users.

Good:

  • Clean separation: first pass identifies files, second pass processes them
  • Folder title is overridden by document title if present (intuitive)
  • No debug output, collision detection preserved (unlike upstream)
  • Proper type annotations

Concerns:

  1. Implicit behavior — no opt-in flag. A user with docs.md next to docs/ might not expect their file to become folder content. Consider adding an opt-in flag like --folder-content-from-file or making this controllable via .pages
  2. Double directory walk — adds a full os.walk pass. For large trees this could be noticeable. Could optimize by collecting subdirs in the main loop instead
  3. Edge case: what if the matching file has front matter labels? Those won't be applied to the folder page since Page.__init__ for folders doesn't pass labels through

Recommendation: Consider making this opt-in. The implicit behavior matches some static site generators but could surprise Confluence users who intentionally have both a folder and a file with the same name for different purposes.

When a markdown file shares its stem with a sibling directory
(e.g., sub-folder.md next to sub-folder/), use its content as the
body of the folder page instead of creating an empty folder page and
a separate content page.

Opt-in via --use-folder-content-file flag. Labels from the matching
file's front matter are passed through to the folder page.

Adapted from iamjackg/md2cf#141 by @sheyifan.
@geopanther

Copy link
Copy Markdown
Owner Author

Updated — addressed all review feedback:

  1. Opt-in behavior — added --use-folder-content-file CLI flag. No implicit behavior change without it
  2. Pre-scan walk skipped when flag is disabled (no perf impact when not using the feature)
  3. Labels from front matter now passed through to folder page via folder_page_labels
  4. New test verifying default behavior is unchanged (test_get_pages_from_directory_folder_content_disabled_by_default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant